package bacnetnetwork1;

import com.serotonin.bacnet4j.LocalDevice;
import com.serotonin.bacnet4j.exception.BACnetServiceException;
import com.serotonin.bacnet4j.obj.BACnetObject;
import com.serotonin.bacnet4j.type.enumerated.ObjectType;
import com.serotonin.bacnet4j.type.enumerated.PropertyIdentifier;
import com.serotonin.bacnet4j.type.primitive.CharacterString;
import com.serotonin.bacnet4j.type.primitive.Real;


public class SSM extends LocalDevice{
    
    
    public SSM(int ID, String networkAddress, String deviceAddress, int port, String name, int outputsNumber) {
        super(ID, networkAddress, deviceAddress);
        
        try {       

        this.getConfiguration().setProperty(PropertyIdentifier.objectName, new CharacterString(name));
        this.setPort(port);        
        
        for (int i=1;i<outputsNumber+1;i++) {
            BACnetObject ao = new BACnetObject(this, this.getNextInstanceObjectIdentifier(ObjectType.analogOutput));
            ao.setProperty(PropertyIdentifier.objectName, new CharacterString("SSM output "+i));
            ao.setProperty(PropertyIdentifier.relinquishDefault, new Real(0.0000F));
            this.addObject(ao);
        }
        

        // Start Device
        this.initialize(); 
        }
        catch (Exception e) {System.out.println(e);}

    }
    
    public void setOutputValue(int outputID, double givenValue) throws BACnetServiceException {
        BACnetObject ao=this.getObject("SSM output "+outputID); 
        ao.setProperty(PropertyIdentifier.presentValue, new Real((float)givenValue));
    }
    
    
}

